package client_tests;

import java.io.*;
import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * User: luke
 * Date: 8/30/13
 * Time: 12:28 PM
 * To change this template use File | Settings | File Templates.
 */
public class ResultTransmitter {

    TreeMap<String, ArrayList<String>> map = new TreeMap<String, ArrayList<String>>();

    //TODO: format according to coordinator specification

    public synchronized void add(String key, String type, String duration, String status) {

        ArrayList<String> list = new ArrayList<String>();
        list.add(type);
        list.add(duration);
        list.add(status);

        map.put(key, list);
    }

    public synchronized void addAll(ResultTransmitter rx) {

        TreeMap<String, ArrayList<String>> sourceMap = rx.getMap();

        for (String key : sourceMap.keySet()) {

            if (map.containsKey(key)) {

                map.put("(copy)" + key, sourceMap.get(key));
            } else {

                map.put(key, sourceMap.get(key));
            }
        }
    }

    public TreeMap<String, ArrayList<String>> getMap() {

        return this.map;
    }

    public void print() {

        ArrayList<String> values = new ArrayList<String>();
        String results = "";
        for (String key : map.keySet()) {

            values.clear();
            values = map.get(key);

            results += key;
            for (String v : values) {

                results += ":" + v;
            }
            results += "\n";
        }

        System.out.println(results);
    }
}
